<template>
  <a-modal :open="open" width="640px" title="复制排班" centered :ok-button-props="{ disabled: !isCompleted }" ok-text="保存" @ok="onOk" @cancel="onCancel">
    <a-form class="form-style-flex" name="validate_other" :model="formState">
      <a-form-item label="截止日期" class="w-1/2" v-bind="validateInfos.endDate">
        <a-date-picker v-model:value="formState.endDate" placeholder="请选择" value-format="YYYY-MM-DD" />
      </a-form-item>
      <a-form-item label="备注" class="w-full">
        <a-textarea v-model:value="formState.memo" :rows="6" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import dayjs from 'dayjs'
import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'success'])
const props = defineProps({
  open: Boolean,
  department: {
    type: Array,
    default: () => []
  }
})

const formState = ref({
  endDate: ''
})
const rulesState = ref({
  endDate: [{ required: true, message: '请选择截止日期' }]
})
const { isCompleted, validateInfos } = useForm(formState, rulesState)

const onOk = async () => {
  const { code, msg } = await post('/inp/InpNursingScheduling/doCopyInpNursingScheduling', {
    bm: props.department,
    date: dayjs().format('YYYY-MM-DD'),
    ...formState.value
  })
  if (code !== 0) return message.error(msg)
  message.success(msg)
  emit('success')
  onCancel()
}

const onCancel = () => {
  emit('update:open', false)
}

watch(
  () => props.open,
  () => {
    formState.value = {}
  }
)
</script>
<style lang="less" scoped></style>
